<?php


namespace app\api\controller;


use think\Db;

class Huodong
{
    /*
     * 通过门店id获取最新的活动
     * */
    public function getInfoByStoreID()
    {
        $store_id=$_POST['store_id'];
        $res=Db::query("select * from fa_huodong where store_id='$store_id' order  by id desc limit 1");
        if (count($res)>0)
        {
            echo json_encode($res);

        }else{


        }
    }


    /*
     * 活动报名
     * */

    public function baoming()
    {
        if (!isset($_POST['name']) || !isset($_POST['phone']) || !isset($_POST['uid']) ||!isset($_POST['huodong_id']) ||!isset($_POST['price']) )
        {
            $result=[
                'code'=>2,
                'msg'=>'err'
            ];
            echo json_encode($result);
            exit();
        }

        $name=$_POST['name'];
        $phone=$_POST['phone'];
        $uid=$_POST['uid'];
        $huodong_id=$_POST['huodong_id'];
        $price=$_POST['price'];
        $pay_type=$_POST['pay_type'];
        $add_time=date('Y-m-d H:i:s');
        $res=Db::name("huodong_baoming")->insert(array(
            'name'=>$name,
            'phone'=>$phone,
            'uid'=>$uid,
            'huodong_id'=>$huodong_id,
            'price'=>$price,
            'add_time'=>$add_time,
            'pay_type'=>$pay_type
        ));
        if ($res>0)
        {
            $result=[
                'code'=>1,
                'msg'=>'ok'
            ];
        }else{
            $result=[
                'code'=>0,
                'msg'=>'err'
            ];
        }

        echo json_encode($result);
        exit();
    }

}